package com.peng.crm.workbench.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.peng.crm.workbench.dao.CustomerDao;
import com.peng.crm.workbench.entity.Customer;
import com.peng.crm.workbench.service.CustomerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 客户(Customer)表服务实现类
 *
 * @author makejava
 * @since 2022-07-02 19:11:34
 */
@Service("customerService")
public class CustomerServiceImpl implements CustomerService {
    @Resource
    private CustomerDao customerDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Customer queryById(String id) {
        return customerDao.quertyById(id);
    }

    /**
     * 通过ID查询单条数据，找到其中关联的ID对应的值  字典表与用户表
     * @param id
     * @return
     */
    public Customer selectById(String id){
        return null;
    }

    /**
     * 根据客户名称查询数据
     * @return
     */
    @Override
    public Customer listCustomerName(String name) {
        Customer customer =  customerDao.listCustomerName(name);
        return customer;
    }

    /**
     * 分页查询
     *
     * @param pageNumber    页码
     * @param pageSize      条数
     * @return 查询结果
     */
    @Override
    public Map<String, Object> listPage(Integer pageNumber, Integer pageSize, Customer customer) {
        PageHelper.startPage(pageNumber,pageSize);
        PageInfo<Customer> pageInfo = new PageInfo(customerDao.select(customer));
        Map<String, Object> pageMap = new HashMap<>();
        pageMap.put("list",pageInfo.getList());
        pageMap.put("total",pageInfo.getTotal());
        return pageMap;
    }

    /**
     * 新增数据
     *
     * @param customer 实例对象
     * @return 实例对象
     */
    @Override
    public Boolean insert(Customer customer) {
        return customerDao.insert(customer)>0;
    }

    /**
     * 修改数据
     *
     * @param customer 实例对象
     * @return 实例对象
     */
    @Override
    public Boolean update(Customer customer) {
        return customerDao.update(customer)>0;
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String id) {
        return this.customerDao.deleteById(id) > 0;
    }

    /**
     * 删除多条数据
     * @param ids   主键数组
     * @return
     */
    @Override
    public boolean removeBatch(String[] ids) {
        return customerDao.deletes(ids);
    }
}
